
#drafted by Lauren Hodgson ( lhodgson86@gmail.com ...  )
#GNU General Public License .. feel free to use / distribute ... no warranties

#use for changing the extent of a large number of ascii files
################################################################################
library(SDMTools);  #load the necessary libraries
wd='/home/ctbccr/Ramona/MoreSubstr/old/';setwd(wd)#define and set the working directory

files=list.files()

sh.dir='/home/ctbccr/Ramona/scripts/sh/' #dir to write sh scripts to
for (tfile in files){ cat(tfile, '\n')
	setwd(sh.dir)
	##create the sh file
	 zz = file(paste(tfile,'.sh',sep=''),'w')
		 cat('#!/bin/bash\n',file=zz)
		 cat('cd $PBS_O_WORKDIR\n',file=zz)
		 cat("R CMD BATCH --no-save --no-restore '--args tfile=\"",tfile,"\" ' /home/ctbccr/Ramona/scripts/00.run_ascii_extent.r ",tfile,'.Rout \n',sep='',file=zz) #run the R script in the background
	close(zz) 

	##submit the script
	system(paste('qsub -m n ',tfile,'.sh',sep=''))
	}

